package com.tencent.sr.iris.basic.saas.service.model.operate;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.tencent.sr.iris.activity.interfaces.response.group.AdvisorBoardResponse;
import com.tencent.sr.iris.basic.saas.common.enums.IrisTaskStatusEnum;
import com.tencent.sr.iris.basic.saas.common.enums.IrisTaskTypeEnum;
import com.tencent.sr.iris.basic.saas.common.utils.CommonUtils;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@ApiModel(value = "导师身份-团长任务列表导出信息")
@Slf4j
@ColumnWidth(15)
public class OperateBoardExportInfo {

    @ExcelProperty(value = "序号", index = 0)
    private int num;

    /**
     * 1=邀新有礼，3=GMV冲刺赛，4=销量冲刺赛
     */
    @ExcelProperty(value = "任务类型", index = 1)
    private String taskTargetEvaluation;

    @ExcelProperty(value = "费用类型", index = 2)
    private String costType;

    @ExcelProperty(value = "任务的开始时间", index = 3)
    private String taskPhaseStartTime;

    @ExcelProperty(value = "任务结束时间", index = 4)
    private String taskPhaseEndTime;

    @ExcelProperty(value = "任务名称", index = 5)
    private String taskPhaseName;

    /**
     * 1=准备中, 2=待上线，3=已上线，4=已下线，5=已作废
     */
    @ExcelProperty(value = "任务状态", index = 6)
    private String taskPhaseStatus;

    @ExcelProperty(value = "可报名团长数", index = 7)
    private Integer canJoinTaskCount;

    @ExcelProperty(value = "报名团长数", index = 8)
    private Integer taskPhaseLeaderLimit;

    @ExcelProperty(value = "报名率(%)", index = 9)
    private Double joinTaskRate;

    @ExcelProperty(value = "预估奖励金", index = 10)
    private Double sumPredictAwardAmount;

    @ExcelProperty(value = "实际奖励金", index = 11)
    private Double sumAwardAmount;

    public void readFromSearchResponseData(AdvisorBoardResponse response) {

        handleCostType(response);

        this.setTaskTargetEvaluation(IrisTaskTypeEnum.getByType(response.getTaskTargetEvaluation()));
        this.setTaskPhaseStartTime(response.getTaskPhaseStartTime());
        this.setTaskPhaseEndTime(response.getTaskPhaseEndTime());
        this.setTaskPhaseName(response.getTaskPhaseName());
        this.setTaskPhaseStatus(IrisTaskStatusEnum.getByStatus(response.getTaskPhaseStatus()));
        this.setTaskPhaseLeaderLimit(response.getTaskPhaseLeaderJoinCount());
        this.setCanJoinTaskCount(response.getCanJoinTaskCount());
        this.setJoinTaskRate(response.getJoinTaskRate());
        this.setSumPredictAwardAmount(CommonUtils.longToDouble(response.getSumPredictAwardAmount()));
        this.setSumAwardAmount(CommonUtils.longToDouble(response.getSumAwardAmount()));
    }

    /**
     * 处理费用类型
     *
     * @param response
     */
    private void handleCostType(AdvisorBoardResponse response) {
        IrisTaskTypeEnum type = IrisTaskTypeEnum.getEnumByType(response.getTaskTargetEvaluation());
        if (type == null) {
            this.setCostType("");
            return;
        }
        switch (type) {
            case INVITE_NEW_FIRST_PURCHASE:
            case FIRST_ORDER:
            case AWARD_TOOL:
                this.setCostType("推广费类");
                break;
            case GMV_SPRINT:
            case SALES_VOLUME_SPRINT:
            case COMMISSION_ROLLBACK:
            case NORMAL_GROUP:
            case SPECIAL_GROUP:
            case GMV_RANK:
            case COMMISSION_RANK:
            case SPECIAL_SPRINT:
            case SALE_SPRINT:
            case NEW_SALE_SPRINT:
                this.setCostType("成本类");
                break;
            default:
                this.setCostType("");
        }
    }

}
